//
//  TXCUrl.m
//  SuperPlayer
//
//  Created by annidyfeng on 2018/9/17.
//  Copyright © 2018年 annidy. All rights reserved.
//

#import "TXCUrl.h"

@implementation TXCUrl
{
    NSURL *m_url;
    NSString *m_bizId;
}

- (instancetype)initWithString:(NSString *)url
{
    self = [super init];

    m_url = [NSURL URLWithString:url];

    return self;
}

- (NSInteger)bizid
{
    if (!m_bizId && m_url) {
        NSString *bizId = nil;
        for (NSString *param in [m_url.query componentsSeparatedByString:@"&"]) {
            NSArray *elts = [param componentsSeparatedByString:@"="];
            if ([elts count] != 2) continue;

            if ([[elts firstObject] isEqualToString:@"bizid"]) {
                bizId = [elts lastObject];
                break;
            }
        }
        if (bizId == nil) {
            bizId = [[m_url host] componentsSeparatedByString:@"."].firstObject;
        }
        m_bizId = bizId;
    }

    return [m_bizId integerValue];
}

@end
